<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>unwrap()</title>
    <script src="../jquery-3.4.1.js"></script>
    <style>
        .left,
        .right {
            width: 250px;
            height: 120px;
        }

        .left div,
        .right div {
            width: 100px;
            height: 120px;
            padding: 5px;
            margin: 5px;
            float: left;
            border: 1px solid #ccc;
            background: #bbffaa;
        }

        .right div {
            background: yellow;
        }
        p {
            border: 1px solid red;
        }

        a {
            border: 1px solid blue;
        }
    </style>
</head>
<body>
    <h2>DOM包裹unwrap()方法</h2>
    <div class="left">
        <button class="aaron1">点击,通过unwrap方法给p元素删除父容器div</button>
        <button class="aaron2">点击,通过unwrap的回调方法给a元素删除父容器div</button>
    </div>
    <div class="right">
        <div>
            <p>p元素</p>
        </div>
        <div>
            <p>p元素</p>
        </div>
    </div>
    <div class="left">
        <div>
            <a>a元素</a>
        </div>
        <div>
            <a>a元素</a>
        </div>
    </div>
</body>

<script>
    $(".aaron1").on("click",function () {
        $('p').unwrap()
    });

    $(".aaron2").on("click",function () {
        $('a').unwrap(function () {
            return "<div></div>"
        })
    })
</script>
</html>